#ifndef __KX_NEURALNETCONTROLLER
#define __KX_NEURALNETCONTROLLER

#include "SCA_IController.h"
#include "stdio.h"

typedef struct Neuron
{
	float error;
    float weightSave;		 /* - saved weights for stopped training  */
    float dWeight;			 /* - last weight deltas for momentum     */
	float* weight;
	float value;
}Neuron;

typedef struct LAYER{     /* A LAYER OF A NET:                     */
        vector<Neuron>	Neurons;				/* Neurons on the layer */
} LAYER;


class SCA_NeuralNetController : public SCA_IController
{
//	Py_Header;
	short				m_type;
	int					m_nblayers;
	int					m_nbinputs;
	int					m_nbhidden;
	int					m_nboutputs;
	float				m_threshold;
	bool				m_isTrained;
	int					m_nbiterations;
	float				m_learningRate;
	float				m_momentumFactor;
	float				**m_lastChangeOutput;
	float				**m_lastChangeInput;
	vector<int>			m_patternInputValues;
	vector<int>			m_patternOutputValues;
	LAYER*				mao_layers;
public:
	SCA_NeuralNetController(SCA_IObject* gameobj,short nntype,float nnthreshold, PyTypeObject* T=&Type );

	virtual ~SCA_NeuralNetController();
	virtual CValue* GetReplica();
	virtual void Trigger(SCA_LogicManager* logicmgr);
	virtual CValue*		FindIdentifier(const STR_String& identifiername);

	void TriggerPerceptron(SCA_LogicManager* logicmgr);
	void TriggerBackPropagation(SCA_LogicManager* logicmgr);
	void TrainNetwork();

	int		getInputs();
	void	SetPatternText(const STR_String& text);
	void	SetPatternName(const STR_String& name);
	float	Sigmoid(float);
	float	dSigmoid(float);
	float	BackPropagate(float*,float*);
	void	UpdateNetwork(float*);
	void	ReadPattern();
	void	RandomWeights();						// Randomize the weights of each neuron in the net

protected:

	STR_String				m_patternText;
	STR_String				m_patternName;


	


	/* --------------------------------------------------------------------- */
	/* Python interface ---------------------------------------------------- */
	/* --------------------------------------------------------------------- */

//	virtual PyObject* py_getattro(PyObject *attr);
//	virtual PyObject* py_getattro_dict();

};

#endif //__KX_NEURALNETCONTROLLER

